package com.briup.mybatis02code.mapper;

import com.briup.mybatis02code.entity.ESUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import javax.xml.crypto.Data;
import java.sql.Date;
import java.util.List;

@Mapper
@Component
public interface ESUserMapper {
    /**
     * 通过id去删除
     * @param id  主键
     */
    @Delete("delete from es_user where id=#{id}")
    void  deleteById(Integer id);

    /**
     * 数据插入
     * @param user 插入的数据合集
     */
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    @Insert("insert into es_user(id,username,password,phone,gender,status,birthday,register_time,avatar) values(seq_test1.nextval,#{username},#{password},#{phone},#{gender},#{status},#{birthday},#{registerTime},#{avatar})")
    void   save(ESUser user);


    @Update("update es_user set username=#{username},password=#{password},gender=#{gender},phone=#{phone},birthday=#{birthday},avatar=#{avatar},status=#{status} where id=#{id}")
    void  update(ESUser user);

//    @Select("select id,username,password,phone,status,avatar,gender,birthday,register_time registertime  from es_user where id=#{id}")
    @Results(@Result(column = "register_time",property = "rt"))
    @Select("select * from es_user where id=#{id}")
    ESUser findById(Integer id);

    @Select("select *  from es_user where username like #{username} and status=#{status}  and register_time between #{start}  and #{end}")
    List<ESUser> findByCondition(String username, int status, @Param("start") Date startDate,@Param("end") Date endDate);

    List<ESUser> findByCondition1(String name, Integer status, Date start, Date end);

    void  dynamicUpdate(ESUser user);

    void  deleteByIds(List<Integer> ids);

    List<ESUser> findAll2();
}
